package com.qf.service.serviceImpl;

import com.qf.dao.UserDao;
import com.qf.pojo.User;
import com.qf.service.UserService;
import com.qf.util.Constants;

/**
 * @author 86198
 * @version V1.0
 * @Project Java_qf
 * @Package com.qf.service.serviceImpl
 * @Description:
 * @Date 2022/5/27 19:31
 */
public class UserServiceImpl implements UserService {
    private UserDao userdao;
    public UserServiceImpl(UserDao userdao){
        this.userdao = userdao;
    }
    @Override
    public User selectUser(String username, String password) {
        User user = userdao.selectUser(username);
        //判断查找出来的 user 密码是否与用户输入的密码相同
        if (!user.getPassword().equals(password)) {
            return null;
        }
        //判断状态是否为活跃 1为活跃
        if (user.getState() != Constants.ACTIVE_SUCCESS) {
            return null;
        }
        return user;
    }

    @Override
    public boolean insertUser(String username, String password) {
        User user = new User();
        user.setPassword(password);
        user.setUsername(username);
        user.setState(Constants.ACTIVE_SUCCESS);
        int results   = userdao.inserteUser(user);
        if (results > 0 ) {
            return true;
        }
        return false;
    }
}
